package com.uuj.dome.controller;

import com.uuj.dome.bean.UserEntity;
import com.uuj.dome.jsp.UserJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:UserController
 * PACKAGE_NAME:com.uuj.dome.controller
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserJpa jpa;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<UserEntity> list() {
        return jpa.findAll();
    }

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public UserEntity save(UserEntity entity) {
        return jpa.save(entity);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public List<UserEntity> delete(int id) {
        jpa.deleteById(id);
        return jpa.findAll();
    }


}
